<template>
  <div style="margin-top:-18px;">
    <a-card :bordered="false">
      <div class="table-page-search-wrapper" >
        <a-form layout="inline" class="formModel" style="margin:20px 0 0 20px">
          <a-row :gutter="48">
            <a-col :md="4" :sm="24">
              <a-form-item label="项目名称">
                <a-input v-model="queryParam.projectName" placeholder="" />
              </a-form-item>
            </a-col>
            <a-col :md="4" :sm="24">
              <a-form-item label="区县">
                <a-input v-model="queryParam.country" placeholder="" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="日期">
                <a-range-picker :ranges="{ Today: [moment(), moment()], 'This Month': [moment(), moment().endOf('month')] }" v-model="selectTime" @change="onChange" class="rangePicker" />
              </a-form-item>
            </a-col>          
            <a-col :md="4" :sm="24">
                <a-form-item label="资源类型">          
                <a-select v-model="queryParam.status" >
                  <a-select-option :value="0">标准视频</a-select-option>
                  <a-select-option :value="1">平安福州</a-select-option>            
                </a-select>            
                </a-form-item>
              </a-col>
            <a-col :md="4" :sm="24">         
                <a-button  type="primary" @click="daochu">excel导出</a-button>                     
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
  </div>
</template>

<script>
import moment from 'moment'
import { getNowTime, getNowFormatDate } from '@/utils/util.js'
import {exportExcelVideo,exportExcelMonitor} from '@/api/video'
const data = []
export default {
  components: {},
  data() {
    return {
      startTime:"",
      endTime:"",
      selectTime:'',
      columnstable,
      data,
      searchData: [],
      // create model
      visible: false,
      confirmLoading: false,
      mdl: null,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {status:0},
      // 加载数据方法 必须为 Promise 对象
      selectedRowKeys: [],
      selectedRows: [],
    }
  },
  filters: {
   
  },
  created() {
    let nowtime = getNowFormatDate()
    this.selectTime = [moment(nowtime), moment(nowtime)]
    this.queryParam.startTime = nowtime+" 00:00:00"
    this.queryParam.endTime = nowtime+" 23:59:59"
  },
  computed: {
    
  },
  mounted(){
   
   
  },
  methods: {
    moment,
    onChange(date, dateString) {  
      this.startTime = dateString[0]
      this.endTime = dateString[1]
      this.selectTime = [moment(dateString[0]), moment(dateString[1])]
      this.queryParam.startTime = dateString[0]+" 00:00:00"
      this.queryParam.endTime = dateString[1]+" 23:59:59"
    },
   daochu(){
    this.queryParam.status==0 ? this.downloadVideo() : this.downloadMonitor()    
   },
   downloadVideo(){
      exportExcelVideo(this.queryParam)
        .then((response) => {
          let blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
          let url = window.URL.createObjectURL(blob)
          let aLink = document.createElement('a')
          aLink.style.display = 'none'
          aLink.href = url
          aLink.setAttribute('download', '标准视频.xlsx')
          document.body.appendChild(aLink)
          aLink.click()
          document.body.removeChild(aLink)
          window.URL.revokeObjectURL(url)
          this.$message.success(`文件已导出`)
        })
        .catch((error) => {})
    },
    downloadMonitor(){
      exportExcelMonitor(this.queryParam)
        .then((response) => {
          let blob = new Blob([response], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
          let url = window.URL.createObjectURL(blob)
          let aLink = document.createElement('a')
          aLink.style.display = 'none'
          aLink.href = url
          aLink.setAttribute('download', '平安福州.xlsx')
          document.body.appendChild(aLink)
          aLink.click()
          document.body.removeChild(aLink)
          window.URL.revokeObjectURL(url)
          this.$message.success(`文件已导出`)
        })
        .catch((error) => {})
    },


   
  },
}
const columnstable = [
  {
    title: '区域',
    dataIndex: 'name1',
    width: 100,
    align: 'center',
  },
  {
    title: 'SLA等级',
    dataIndex: 'name', 
    width: 100,
    align: 'center',
  },
  {
    title: '室内',
    dataIndex: 'name2', 
    width: 100,
    align: 'center',
  },
   {
    title: '室外道路',
    dataIndex: 'name3', 
    width: 100,
    align: 'center',
  },
   {
    title: '室外非道路',
    dataIndex: 'name4', 
    width: 100,
    align: 'center',
  },
   {
    title: '一键报警',
    dataIndex: 'name5', 
    width: 100,
    align: 'center',
  },
  {
    title: '合计路数',
    dataIndex: 'name6', 
    width: 100,
    align: 'center',
  },
  
 
]
</script>
